<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>类型增加</title>
  <link rel="stylesheet" type="text/css" href="res/css/common/layui/css/layui.css" media="all">
<style type="text/css">
	
</style>
</head>
<body>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
  <legend>类型增加列表</legend>
</fieldset>
 
<form class="layui-form" action="GoodsTypeServlet?action=add" method="post">
	
  <div class="layui-form-item">
    <div class="layui-inline">
      <label class="layui-form-label">商品类型自关联</label>
      <div style="display: inline-block; width: 180px; height: 100%; padding: 10px; overflow: auto;">
     	<input  class="layui-input layui-disabled" id="goodType" disabled>
      	<input type='hidden' id="goodsTypePid" name="goodsTypePid">
   		<ul id="goodsTypeTree"></ul>
      </div>
    
      </div>
  </div>
	
   <div class="layui-form-item">
    <label class="layui-form-label">类型名称</label>
    <div class="layui-input-block">
      <input lay-verify="title" autocomplete="off" placeholder="请输入需要增加的类型名称" name="goodsTypeName" class="layui-input" type="text">
    </div>
  </div>
  
  
 
  <div class="layui-form-item">
    <div class="layui-input-block">
      <input type="submit" class="layui-btn" lay-submit="" lay-filter="typeAdd" value="立即提交">
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
  
  
</form>


          
<script type="text/javascript" src="res/css/common/layui/layui.all.js"></script>
<script type="text/javascript" src="res/js/jquery.min.js"></script>
<script>
layui.use(['form','tree','layer'], function(){
  var form = layui.form
  ,layer = layui.layer
  ,$ = layui.$;
  form.on('submit(typeAdd)',function(){
	  parent.location.reload(); // 父页面刷新
  });
  var url="GoodsServlet";
  var data= {action:'tree'};
  $.post(url,data,function(data){
	  eval("var data="+data);
	  layui.tree({
		  elem: '#goodsTypeTree' //传入元素选择器
		  ,nodes: data
		  ,click: function(node){
			 $("#goodType").val(node.name);
			 
			 $("#goodsTypePid").val(node.id);
		  }  
	 });
  });
  
});



var datatree = null ;

$.ajax({
	url:"GoodsTypeServlet",
	data:{action:"findType",pid:pid},
	success: function(m){
		   console.info(m);
			if(m.length>0){ //如果没有下级,则结束递归
				$("#"+elementId).append("<ul class='c_"+pid+"'></ul>");
				//将数据循环出来
				$.each(m,function(index,item){	
					//alert(index);
					$(".c_"+pid).append("<li id='"+item.goodsTypeId+"' ><a href='javascript:void(0);' onclick='showType(this);' id='"+item.goodsTypeId+"'>"+item.goodsTypeName+"</a></li>");
					showMenu(item.goodsTypeId,item.goodsTypeId); //递归
				});
			} 
	   }
});

	
</script>

</body>
</html>